#include "samename.h"
#include "ui_samename.h"
#include <QDebug>
#include <QSqlQuery>
#include <QSqlQueryModel>
samename::samename(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::samename)
{
    ui->setupUi(this);
    ui->table->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->table->setEditTriggers(QAbstractItemView::NoEditTriggers);
}

samename::~samename()
{
    delete ui;
}

void samename::on_pushButton_clicked()//重名干部查询
{
    QString name=ui->nametext->text();
    //QSqlQueryModel *mod = new QSqlQueryModel(this);
    QSqlQuery query;
    //mod->setQuery(QString("select CadreName,IDNum from CadreInfo where CadreName='%1'").arg(name));
    query.exec(QString("select CadreName,IDNum from CadreInfo where CadreName='%1'").arg(name));//where定义查询条件
    while(query.next())
    {
        int rowcount=ui->table->rowCount();//有几列
        ui->table->insertRow(rowcount);//加一行table
        QString CadreName=query.value(0).toString();//0
        ui->table->setItem(rowcount,0,new QTableWidgetItem(CadreName));
        QString IDNum=query.value(1).toString();//1
        ui->table->setItem(rowcount,1,new QTableWidgetItem(IDNum));
    }
}

void samename::on_table_doubleClicked()
{
//   // qDebug()<<"test";
    int row = ui-> table ->currentIndex().row();
    int i=1;
    QVariant id = ui->table->item(row,i)->text();
    QString iddate=id.toString();
//    shangbao=new Form1;
//    connect(this,SIGNAL(senddata(QString)),shangbao,SLOT(recvData(QString)));
    emit sendData1(iddate);//发送id
    this->close();
//    emit sendData(iddate);//发送lineEdit中的文本，sendData信号
}
